package com.jwm.platform.db;

import com.jwm.util.AjaxResult;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author 崔洁
 */
@RestController
@RequestMapping(value = "/warning")
public class Warning {
    @Resource
    private BaseDao baseDao;

    @PostMapping("/add")
    @ResponseBody
    public AjaxResult add(@RequestBody WarningVo vo) {
        try {
            int i = baseDao.addBase(vo);
            return AjaxResult.success(i);
        } catch (Exception e) {
            return AjaxResult.error(e.getMessage());
        }
    }

    @PostMapping("/update")
    @ResponseBody
    public AjaxResult update(@RequestBody WarningVo vo) {
        try {
            int i = baseDao.modifyBase(vo);
            return AjaxResult.success(i);
        } catch (Exception e) {
            return AjaxResult.error(e.getMessage());
        }
    }

    @GetMapping("/removeById")
    @ResponseBody
    public AjaxResult removeById(Integer id) {
        int i = baseDao.deleteBase(WarningVo.class, id);
        return AjaxResult.success(i);
    }

    @GetMapping("/list")
    @ResponseBody
    public AjaxResult list() {
        List<WarningVo> list = baseDao.queryList(new WarningVo());
        return AjaxResult.success(list);
    }

    @GetMapping("/queryById")
    @ResponseBody
    public AjaxResult queryById(Integer id) {
        WarningVo vo = baseDao.queryById(new WarningVo(), id);
        return AjaxResult.success(vo);
    }
}
